import { Metadata } from "next";
import LoginForm from "./LoginForm";
import { redirect } from "next/navigation";
import { isAuthenticated } from "../actions";
import AppError from "@/shared/app-error";

export const metadata: Metadata = {
  title: "登录",
};

export default async function Page() {
  const authedResult = await isAuthenticated();
  if (!authedResult.ok) {
    throw new AppError({ message: "获取登录信息时出错", code: "ERR_UNHANDLED" });
  }
  const authed = authedResult.data;
  if (authed) {
    redirect("/");
  }

  return (
    <div className="max-w-sm mx-auto py-8 sm:px-0 md:px-8 sm:border-0 md:border sm:shadow-none md:shadow">
      <h1 className="text-3xl mb-4 font-semibold">在此登录</h1>
      <LoginForm />
    </div>
  );
}
